// Copyright (C) <2018> Zealcomm Inc.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IRTC_CONFERENCE_OBJC_IRTCCONFERENCECLIENT_H_
#define IRTC_CONFERENCE_OBJC_IRTCCONFERENCECLIENT_H_
#import <IRTC/IRTCMacros.h>
#import <WebKit/WebKit.h>
#import "IRTC/IRTCConferenceClientConfiguration.h"
#import "IRTC/IRTCConferenceHostInfo.h"
#import "IRTC/IRTCConferenceInfo.h"
#import "IRTC/IRTCConferenceParticipant.h"
#import "IRTC/IRTCConferencePublication.h"
#import "IRTC/IRTCConferenceSession.h"
#import "IRTC/IRTCConferenceSubscription.h"
#import "IRTC/IRTCConferenceWhiteboard.h"
#import "IRTC/IRTCLocalStream.h"
#import "IRTC/IRTCPublishOptions.h"
#import "IRTC/IRTCRemoteMixedStream.h"
#import "IRTC/IRTCRemoteStream.h"
#import "IRTC/IRTCSip.h"
NS_ASSUME_NONNULL_BEGIN
@protocol IRTCConferenceClientDelegate;
/// An asynchronous class for app to communicate with a conference in
/// MCU.<br>用于和MCU的会议进行联系的异步类。
IRTC_OBJC_EXPORT
@interface IRTCConferenceClient
    : NSObject <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler>
/**
  @brief Initialize a IRTCConferenceClient with
  configuration.<br>用配置来初始化IRTCConferenceClient。
  @param config Configuration for creating the
  IRTCConferenceClient.<br>用于创建IRTCConferenceClient的配置参数。
*/
- (instancetype)initWithConfiguration:
    (IRTCConferenceClientConfiguration*)config;
/**
  @brief Set host information to a conference
  client.<br>给会议客户端设置宿主机的信息。
  @param hostInfo Host ip information.<br>宿主机ip相关的信息。
*/
- (void)setHostInfo:(nullable IRTCHostInfo*)hostInfo;
/**
  @brief Connect to the specified room to join a
  conference.<br>连接到某个房间以便加入会议。
  @param token Includes the room info which is
  encrypted.<br>房间令牌，里面包括加密后的房间信息。
  @param onSuccess Success callback with the conference
  info.<br>成功后的回调，含会议信息。
*/
- (void)joinWithToken:(NSString*)token
            onSuccess:(nullable void (^)(IRTCConferenceInfo*))onSuccess
            onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Publish the stream to the current room.<br>发布媒体流到当前房间。
  @param stream The stream to be published.<br>用于发布的媒体流。
*/
- (void)publish:(IRTCLocalStream*)stream
    withOptions:(nullable IRTCPublishOptions*)options
      onSuccess:(nullable void (^)(IRTCConferencePublication*))onSuccess
      onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Subscribe a stream from the current room.<br>从当前房间订阅媒体流。
  @param stream The remote stream to be subscribed.<br>将订阅的远端媒体流。
  @param options Options for subscribing the stream.<br>订阅媒体流时的参数。
  @param onSuccess Success callback with a stream that contains media
  stream.<br>成功后的回调，含订阅的媒体流。
*/
- (void)subscribe:(IRTCRemoteStream*)stream
      withOptions:(nullable IRTCConferenceSubscribeOptions*)options
        onSuccess:(nullable void (^)(IRTCConferenceSubscription*))onSuccess
        onFailure:(nullable void (^)(NSError*))onFailure;

/**
  @brief Send message to all participants in the
  conference.<br>给会议内所有与会者发送消息。
  @param message The message to be sent.<br>用于发送的消息。
*/
- (void)send:(NSString*)message
    onSuccess:(nullable void (^)())onSuccess
    onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Send message to specific participant in the
  conference.<br>给会议内指定与会者发送消息。
  @param message The message to be sent..<br>用于发送的消息。
  @param to The user who receives this message.<br>接收消息的用户。
*/
- (void)send:(NSString*)message
           to:(NSString*)receiver
    onSuccess:(nullable void (^)())onSuccess
    onFailure:(nullable void (^)(NSError*))onFailure;

/**
  @brief Create a whiteboard in the conference.<br>在会议中创建一个白板。
  @param name Name of whiteboard.<br>白板的名字。
  @param path Path of whiteboard.<br>白板的路径。
  @param attributes Attributes of whiteboard.<br>白板的属性。
  @param onSuccess Success callback with a whiteboard that was
  created.<br>成功回调会返回创建的白板。
  @param on_failure Failure callback with an
  exception.<br>失败回调会返回失败原因。
*/
- (void)createWhiteboardWithName:(NSString*)name
                            path:(NSString*)path
                      attributes:(NSDictionary<NSString*, NSString*>*)attributes
                       onSuccess:(nullable void (^)(IRTCConferenceWhiteboard*))
                                     onSuccess
                       onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Start a whiteboard in the conference.<br>在会议中开启一个白板。
  @param whiteboard Whiteboard to be started.<br>要开启的白板。
  @param hostname Host of whiteboard.<br>白板的主机地址。
  @param onSuccess Success callback with a whiteboard that was
  created.<br>成功回调会返回创建的白板。
  @param on_failure Failure callback with an
  exception.<br>失败回调会返回失败原因。
*/
- (void)startWhiteboard:(IRTCConferenceWhiteboard*)whiteboard
               hostname:(NSString*)hostname
              onSuccess:(nullable void (^)(WKWebView*))onSuccess
              onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Stop a whiteboard in the conference.<br>在会议中关闭一个白板。
  @param whiteboard Whiteboard to be stopped.<br>要关闭的白板。
  @param onSuccess Success callback with a whiteboard that was
  created.<br>成功回调会返回创建的白板。
  @param on_failure Failure callback with an
  exception.<br>失败回调会返回失败原因。
*/
- (void)stopWhiteboard:(IRTCConferenceWhiteboard*)whiteboard
             onSuccess:(nullable void (^)(IRTCConferenceWhiteboard*))onSuccess
             onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Remove a whiteboard in the conference.<br>在会议中删除一个白板。
  @param whiteboard Whiteboard to be removed.<br>要删除的白板。
  @param onSuccess Success callback with a whiteboard that was
  created.<br>成功回调会返回创建的白板。
  @param on_failure Failure callback with an
  exception.<br>失败回调会返回失败原因。
*/
- (void)removeWhiteboard:(IRTCConferenceWhiteboard*)whiteboard
               onSuccess:(nullable void (^)(IRTCConferenceWhiteboard*))onSuccess
               onFailure:(nullable void (^)(NSError*))onFailure;

/**
  @brief Capture snapshot a whiteboard in the
  conference.<br>捕获会议中的白板快照。
  @param whiteboard Whiteboard to capture snapshots.<br>要捕获快照的白板。
  @param onSuccess Success callback with a snapshots info that was
  created.<br>成功回调会返回快照的信息。
  @param on_failure Failure callback with an
  exception.<br>失败回调会返回失败原因。
*/
- (void)snapshot:(IRTCConferenceWhiteboard*)whiteboard
       onSuccess:(nullable void (^)(IRTCSnapshotInfo*))onSuccess
       onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Leave current conference.<br>离开当前会议。
*/
- (void)leaveWithOnSuccess:(nullable void (^)())onSuccess
                 onFailure:(nullable void (^)(NSError*))onFailure;
@property(nonatomic, weak) id<IRTCConferenceClientDelegate> delegate;
@end
/// Delegate for
/// IRTCConferenceClient.<br>IRTCConferenceClient的Delegate（代理）。
IRTC_OBJC_EXPORT
@protocol IRTCConferenceClientDelegate <NSObject>
@optional
/**
  @brief Triggers when client is reconnected from conference
  server.<br>当客户端和会议服务器恢复连接时触发。
*/
- (void)conferenceClientDidReconnect:(IRTCConferenceClient*)client;
/**
  @brief Triggers when client is disconnected from conference
  server.<br>当客户端和会议服务器断开连接时触发。
*/
- (void)conferenceClientDidDisconnect:(IRTCConferenceClient*)client;
/**
  @brief Triggers when a stream is added.<br>当有新的媒体流加入时触发。
  @param stream The stream which is added.<br>新加入的媒体流。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
            didAddStream:(IRTCRemoteStream*)stream;
/**
  @brief Triggers when a message is received.<br>当接收到新的消息时触发。
  @param senderId Sender's ID.<br>发送者的ID。
  @param message Message received.<br>接收到的消息。
  @param targetType "all" if broadcast message. "me"
  if the message is sent only to current conference
  client.<br>如果是"all"则是广播消息；如果是"me"则是指定发送目标的消息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
       didReceiveMessage:(NSString*)message
                    from:(NSString*)senderId
                      to:(NSString*)targetType;
/**
  @brief Triggers when a session added conference.<br>当会议中有新的会话时触发。
  @param session The session added.<br>新加入的会话。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
           didAddSession:(IRTCConferenceSession*)session;
/**
  @brief Session error event callback.<br>会话错误事件回调。
  @param session The session added.<br>新加入的会话。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
         didSessionError:(IRTCConferenceSession*)session;
/**
  @brief Session end event callback.<br>会话结束事件回调。
  @param session The session added.<br>新加入的会话。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
           didSessionEnd:(IRTCConferenceSession*)session;
/**
  @brief Triggers when a user joined conference.<br>当有新的用户加入会议时触发。
  @param user The user joined.<br>新加入的用户。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
       didAddParticipant:(IRTCConferenceParticipant*)user;
/**
  @brief Triggers when a whiteboard added
  conference.<br>当有新的白板加入会议时触发。
  @param user The whiteboard added.<br>新加入的白板。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
        didAddWhiteboard:(IRTCConferenceWhiteboard*)whiteboard;
/**
  @brief A new sip incoming call in the
  conference.<br>一会新的sip来电出现在会议中。
  @param info Sip incoming call information.<br>来电信息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
      didSipIncomingCall:(IRTCSipIncomingInfo*)info;
/**
  @brief A new sip incoming call was cancelled in the
  conference.<br>一会新的sip来电被取消出现在会议中。
  @param info Sip call information cancelled.<br>取消的来电信息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
    didSipIncomingCallCancelled:(IRTCSipIncomingCancelInfo*)info;
/**
  @brief A sip call closed in the
  conference.<br>一会新的sip会话关闭出现在会议中。
  @param info Sip call information closed.<br>关闭的通话信息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
        didSipCallClosed:(IRTCSipCallClosedInfo*)info;
/**
  @brief Sip client registered failed event.<br>Sip终端注册失败事件。
  @param info Sip register information.<br>Sip注册信息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
    didSipRegisteredFailed:(IRTCSipRegisteredInfo*)info;
/**
  @brief DTMF event of sip client.<br>Sip终端DTMF事件。
  @param info Sip DTMF information.<br>Sip DTMF信息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
              didSipDTMF:(IRTCSipDTMFInfo*)info;
@end
NS_ASSUME_NONNULL_END
#endif  // IRTC_CONFERENCE_OBJC_IRTCCONFERENCECLIENT_H_
